Skip to content

fix: ingest-card copies Spec + instances from shared/published source realms#5276

Open
jurgenwerk wants to merge 3 commits into
mainfrom
cs-11652-ingest-card-per-realm-search
Open

fix: ingest-card copies Spec + instances from shared/published source realms#5276
jurgenwerk wants to merge 3 commits into
mainfrom
cs-11652-ingest-card-per-realm-search

Conversation

@jurgenwerk

@jurgenwerk jurgenwerk commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

What was wrong

boxel realm ingest-card copied a card's code modules but not its catalog Spec or sample instances when the source realm was a shared/published one (like the catalog). So the software factory's "adjust an existing card" flow had to reconstruct those by hand on every run — slow, and a lossy approximation of the real card.

Why

Ingest discovered instances + Specs through a profile-scoped search that only covers realms the active profile owns. A shared realm like the catalog isn't in that set, so every discovery query came back empty and ingest fell back to copying modules only. (The module copy survived because it uses direct file fetches, not search.)

What this changes

  • Discovery now queries the source realm's own search endpoint directly, so it works for any reachable realm — shared/published included.
  • A published realm returns matches in a different envelope (in included, with an empty data); a small selectSearchResults helper handles both shapes.

Testing

  • Live: ingesting a catalog card now copies its Spec(s) + sample instances alongside the modules (was modules-only).
  • Unit tests for the result-shape handling; the fake-realm end-to-end test now stubs the realm's own search endpoint.

jurgenwerk and others added 2 commits June 18, 2026 15:08
… realms

ingest-card discovered instances and Specs via the profile-scoped
`_federated-search`, which only covers realms in the active profile's set. A
shared/published source realm (e.g. the catalog) isn't in that set, so every
discovery query returned nothing and ingest copied modules only — forcing the
software factory to reconstruct Specs/instances by hand on every adjust run.
(The module crawl was unaffected because it uses direct file fetches.)

Query the source realm's own `_search` endpoint directly via authedRealmFetch
instead. A published realm returns matches in `included` with an empty `data`,
so `selectSearchResults` prefers `data` and falls back to `included` (never
merges, so a normal realm's linked-dep `included` isn't mistaken for matches).

Verified end-to-end against the live catalog: ingesting the WineCellar card now
copies both Specs + 10 sample instances alongside the 2 modules (was 2 files).

CS-11652.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The fake-realm graph test stubbed the old profile-scoped federated search
(`profileManager.authedRealmServerFetch`); ingest now queries the source
realm's own `_search` via `authedRealmFetch`, so move the instance/Spec stub
there (keyed on `<realm>/_search`) and drop the now-dead profile-manager
search mock.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes boxel realm ingest-card so it can discover and copy a card’s Catalog Specs and sample instances even when the source realm is shared/published (and therefore not in the active profile’s federated-search realm set). It does this by querying the source realm’s own _search endpoint directly and handling the published-realm response shape.

Changes:

  • Switch ingest discovery queries from profile-scoped /_federated-search to the source realm’s /_search via authenticator.authedRealmFetch(...).
  • Add selectSearchResults() to handle the “published realm returns matches in included with empty data” response shape.
  • Update and extend tests (unit coverage for selectSearchResults, and update the fake realm end-to-end ingest test’s _search stub).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/boxel-cli/src/commands/realm/ingest-card.ts Query source realm /_search directly; add selectSearchResults; remove federated-search dependency.
packages/boxel-cli/tests/commands/ingest-card.test.ts Add unit tests for selectSearchResults behavior across response shapes.
packages/boxel-cli/tests/commands/ingest-card-graph.test.ts Update fake authenticator to handle /_search (QUERY) and remove federated-search stubbing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +358 to 362
if (!res.ok) {
this.hasError = true;
console.warn(` search failed: ${result.error ?? 'unknown'}`);
console.warn(` search failed: HTTP ${res.status}`);
return [];
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Written by Claude on Matic's behalf.)

Fixed in 814f807. The _search failure now logs HTTP <status> <statusText> plus a truncated (300-char) response-body snippet, so auth errors / malformed queries are diagnosable from the CLI output — parity with the old federated-search path.

…ilure

The realm `_search` failure path logged only the bare HTTP status; surface
statusText and a truncated response body too, so auth errors / malformed
queries are diagnosable from the CLI output (parity with the previous
federated-search path).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jurgenwerk jurgenwerk marked this pull request as ready for review June 19, 2026 12:04
@jurgenwerk jurgenwerk requested a review from a team June 19, 2026 12:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 814f807c04

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +347 to +357
let res = await this.authenticator.authedRealmFetch(
`${this.realmRoot}_search`,
{
method: 'QUERY',
headers: {
Accept: CARD_JSON,
'Content-Type': 'application/json',
},
body: JSON.stringify(query),
},
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve best-effort behavior when search throws

If the direct _search fetch rejects (for example during token refresh/network failure) or the response body cannot be parsed as JSON, the exception now escapes searchCards() and aborts sync() before downloadAll(), so even the module graph already discovered is not copied. The previous federated search() converted these failures into ok: false, and the surrounding code still treats search as optional via hasError and return []; this direct path should catch fetch/parse failures and use the same warning/empty-result path.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants